import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/28 14:19
 * @description 双指针优化
 */
public class Solution3 {
    public static void main(String[] args) {

    }
    public int maxArea(int[] height) {
        int left = 0, right = height.length - 1;
        int ans = 0;
        while (left < right) {
            ans = Math.max(ans, Math.min(height[left], height[right]) * (right - left));
            if (height[left] < height[right]) {
                // 左边的小
                int h = height[left];
                // 移动过程中左边找到更小的，那么直接排除
                while (left < right && height[left] <= h) {
                    left++;
                }
            }else if (height[left] > height[right]) {
                // 右边的小
                int h = height[right];
                // 同理
                while (right > left && height[right] <= h) {
                    right--;
                }
            }else {
                left++;
                right--;
            }
        }
        return ans;
    }
}
